﻿
/***************************************************************************
* Copyright(C)   2013  Granger Corporation
* All rights reserved
*
* Author: Granger(Granger@haipos.com)
* CreateDate: 2013/7/3 13:12:16
* Description:
*
* Revision History
* Date					Author		Versions		Description
* 2013/7/3 13:12:16	Granger		v1.0
**************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace UNSite.Core.Data
{
    public abstract class DALBase<Entity> where Entity:class,new()
    {       
        ////缓存
        //private Cache.IDataCache icache = null;
        //public virtual Cache.IDataCache ICache
        //{
        //    get { return icache; }
        //    set { icache = value; }
        //}
        
        ////Sql语句构建
        //private ISqlBuilder ibuilder = null;
        //public ISqlBuilder IBuilder
        //{
        //    get { return ibuilder; }
        //    set { ibuilder = value; }
        //}
        
        ////执行数据操作
        //private ISqlHelper ihelper = null;
        //public virtual ISqlHelper IHelper
        //{
        //    get { return ihelper; }
        //    set { ihelper = value; }
        //}


        //public void Init(Cache.IDataCache cache, ISqlBuilder builder,ISqlHelper help)
        //{
        //    ICache = cache;
        //    IBuilder =builder;
        //    IHelper = help;
        
        //}

        /// <summary>
        /// 表名
        /// </summary>
        public abstract string TableName { get; }
        /// <summary>
        /// 主键
        /// </summary>
        public abstract string KeyFieldName { get; }

        #region Query
        /// <summary>
        /// 查询Sql数据
        /// </summary>
        /// <param name="strSql"></param>
        /// <returns>返回DataSet,Null表示执行失败</returns>
        //public DataSet Query(string strSql)
        //{
        //    try
        //    {
        //        Logger.Debug(string.Format("执行查询操作Sql:{0}", strSql));
        //        DataSet dt =IHelper.Query(strSql);
        //        return dt;
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行查询操作失败Sql:{0}", strSql)
        //            , ex);
        //    }
        //    return null;
        //}

        ///// <summary>
        ///// 返回全部
        ///// </summary>
        ///// <returns></returns>
        //public DataSet Query()
        //{
        //    return Query("", "");
        //}

        ///// <summary>
        ///// 根据条件查询当前表
        ///// </summary>
        ///// <param name="where">条件</param>
        ///// <param name="order">排序</param>
        ///// <returns></returns>
        //public DataSet Query(string where, string order)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    sb.AppendFormat("SELECT * FROM [{0}]  ", TableName);
        //    if (!string.IsNullOrEmpty(where)) sb.AppendFormat(" WHERE {0} ", where);
        //    if (!string.IsNullOrEmpty(order)) sb.AppendFormat(" ORDER BY {0} ", order);
        //    return Query(sb.ToString());
        //}


        ///// <summary>
        ///// 根据条件查询当前表的字段
        ///// </summary>
        ///// <param name="field">查询字段</param>
        ///// <param name="where">条件</param>
        ///// <param name="order">排序</param>
        ///// <returns></returns>
        //public DataSet Query(string field, string where, string order)
        //{
        //    StringBuilder sb = new StringBuilder();

        //    if (!string.IsNullOrEmpty(field))
        //    {
        //        sb.AppendFormat("SELECT {1} FROM [{0}]  ", TableName, field);
        //    }
        //    else {
        //        sb.AppendFormat("SELECT * FROM [{0}]  ", TableName);
        //    }

           
        //    if (!string.IsNullOrEmpty(where)) sb.AppendFormat(" WHERE {0} ", where);
        //    if (!string.IsNullOrEmpty(order)) sb.AppendFormat(" ORDER BY {0} ", order);
        //    return Query(sb.ToString());
        //}


        ///// <summary>
        ///// 根据条件查询当前表
        ///// </summary>
        ///// <param name="top">返回记录数</param>
        ///// <param name="where"></param>
        ///// <param name="order"></param>
        ///// <returns></returns>
        //public DataSet Query(int top ,string where, string order)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    sb.AppendFormat("SELECT TOP {0} * FROM [{1}]  ",top, TableName);
        //    if (!string.IsNullOrEmpty(where)) sb.AppendFormat(" WHERE {0} ", where);
        //    if (!string.IsNullOrEmpty(order)) sb.AppendFormat(" ORDER BY {0} ", order);
        //    return Query(sb.ToString());
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="top"></param>
        ///// <param name="where"></param>
        ///// <param name="order"></param>
        ///// <returns></returns>
        //public DataSet Query(int top,string field, string where, string order)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    if (!string.IsNullOrEmpty(field))
        //    {
        //        sb.AppendFormat("SELECT TOP {2} {1} FROM [{0}]  ", TableName, field, top);
        //    }
        //    else
        //    {
        //        sb.AppendFormat("SELECT TOP {1} * FROM [{0}]  ", TableName, top);
        //    }

        //    //sb.AppendFormat("SELECT TOP {0} * FROM [{1}]  ", top, TableName);
        //    if (!string.IsNullOrEmpty(where)) sb.AppendFormat(" WHERE {0} ", where);
        //    if (!string.IsNullOrEmpty(order)) sb.AppendFormat(" ORDER BY {0} ", order);
        //    return Query(sb.ToString());
        //}


        ///// <summary>
        ///// 返回全部 
        ///// </summary>
        ///// <returns></returns>
        //public IList<Entity> QueryList()
        //{
        //    return QueryList(null, null);
        //}

        ///// <summary>
        ///// 根据条件查询当前表
        ///// </summary>
        ///// <param name="where"></param>
        ///// <param name="order"></param>
        ///// <returns>返回实体列表</returns>
        //public IList<Entity> QueryList(string where, string order)
        //{
        //    IList<Entity> ls = new List<Entity>();
        //    DataTable dt = Query(where, order).Tables[0];
        //    foreach (DataRow drv in dt.Rows)
        //    {
        //        ls.Add(ModelConvert.FromDataRow<Entity>(drv));
        //    }
        //    return ls;
        //}

        ///// <summary>
        ///// 根据条件查询当前表
        ///// </summary>
        ///// <param name="top"></param>
        ///// <param name="where"></param>
        ///// <param name="order"></param>
        ///// <returns></returns>
        //public IList<Entity> QueryList(int top,string where, string order)
        //{
        //    IList<Entity> ls = new List<Entity>();
        //    DataTable dt = Query(top,where, order).Tables[0];
        //    foreach (DataRow drv in dt.Rows)
        //    {
        //        ls.Add(ModelConvert.FromDataRow<Entity>(drv));
        //    }
        //    return ls;
        //}


        //public IList<Entity> QueryList(string filed, string where, string order)
        //{
        //    IList<Entity> ls = new List<Entity>();
        //    DataTable dt = Query(filed, where, order).Tables[0];
        //    foreach (DataRow drv in dt.Rows)
        //    {
        //        ls.Add(ModelConvert.FromDataRow<Entity>(drv));
        //    }
        //    return ls;
        //}




        //public IList<Entity> QueryList(int top,string field, string where, string order)
        //{
        //    IList<Entity> ls = new List<Entity>();
        //    DataTable dt = Query(top,field, where, order).Tables[0];
        //    foreach (DataRow drv in dt.Rows)
        //    {
        //        ls.Add(ModelConvert.FromDataRow<Entity>(drv));
        //    }
        //    return ls;
        //}

        //public IList<Entity> QueryList(string strSql)
        //{
        //    IList<Entity> ls = new List<Entity>();
        //    DataTable dt = Query(strSql).Tables[0];
        //    foreach (DataRow drv in dt.Rows)
        //    {
        //        ls.Add(ModelConvert.FromDataRow<Entity>(drv));
        //    }
        //    return ls;
        //}

        ///// <summary>
        ///// 根据ID，查询
        ///// </summary>
        ///// <param name="ID"></param>
        ///// <returns></returns>
        //public Entity QueryModel(int ID)
        //{
        //    return QueryModel(string.Format(" [{0}]={1} ", KeyFieldName, ID));
        //}

        ///// <summary>
        ///// 根据ID，查询
        ///// </summary>
        ///// <param name="ID"></param>
        ///// <returns></returns>
        //public Entity QueryModel(long ID)
        //{
        //    return QueryModel(string.Format(" [{0}]={1} ", KeyFieldName, ID));
        //}

        ///// <summary>
        ///// 根据Where条件查询
        ///// </summary>
        ///// <param name="Where"></param>
        ///// <returns></returns>
        //public Entity QueryModel(string Where)
        //{
        //    return QueryModel(Where, "");
        //}

        // /// <summary>
        ///// 返回第一行的实体
        // /// </summary>
        // /// <param name="strSql">sql语句</param>
        // /// <returns></returns>
        //public DataRow QueryModelBySql(string strSql)
        //{
        //    try
        //    {
        //        DataTable dt = Query(strSql).Tables[0];
        //        if (dt == null || dt.Rows.Count < 1) return null;
        //        return dt.Rows[0];
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("QueryModel失败Sql:" + strSql, ex);
        //    }
        //    return null;
        //}

        ///// <summary>
        ///// 返回第一行的实体
        ///// </summary>
        ///// <param name="where"></param>
        ///// <param name="order"></param>
        ///// <returns></returns>
        //public Entity QueryModel(string where, string order)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    try
        //    {
        //        sb.AppendFormat("SELECT * FROM [{0}]  ", TableName);
        //        if (!string.IsNullOrEmpty(where)) sb.AppendFormat(" WHERE {0} ", where);
        //        if (!string.IsNullOrEmpty(order)) sb.AppendFormat(" ORDER BY {0} ", order);

        //        Logger.Debug("QueryModelSql:" + sb.ToString());

        //        DataTable dt = Query(sb.ToString()).Tables[0];
        //        if (dt == null || dt.Rows.Count < 1) return null;
        //        return ModelConvert.FromDataRow<Entity>(dt.Rows[0]);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("QueryModel失败Sql:" + sb.ToString(), ex);
        //    }
        //    finally
        //    {
        //        sb = null;
        //    }
        //    return null;
        //}


        ///// <summary>
        ///// 返回第一行的实体
        ///// </summary>
        ///// <param name="fileds"></param>
        ///// <param name="where"></param>
        ///// <param name="order"></param>
        ///// <returns></returns>
        //public Entity QueryModel(string fileds, string where, string order)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    try
        //    {
        //        if (!string.IsNullOrEmpty(fileds))
        //        {
        //            sb.AppendFormat("SELECT {1} FROM [{0}]  ", TableName,fileds);
        //        }
        //        else {
        //            sb.AppendFormat("SELECT * FROM [{0}]  ", TableName);
        //        }

        //        if (!string.IsNullOrEmpty(where)) sb.AppendFormat(" WHERE {0} ", where);
        //        if (!string.IsNullOrEmpty(order)) sb.AppendFormat(" ORDER BY {0} ", order);

        //        Logger.Debug("QueryModelSql:" + sb.ToString());

        //        DataTable dt = Query(sb.ToString()).Tables[0];
        //        if (dt == null || dt.Rows.Count < 1) return null;
        //        return ModelConvert.FromDataRow<Entity>(dt.Rows[0]);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("QueryModel失败Sql:" + sb.ToString(), ex);
        //    }
        //    finally
        //    {
        //        sb = null;
        //    }
        //    return null;
        //}

        //#endregion

        //#region Insert
        ///// <summary>
        ///// 执行插入操作
        ///// </summary>
        ///// <param name="strSql">插入脚本</param>
        ///// <param name="IsIdentity">是否返回值</param>
        ///// <returns>-1操作失败</returns>
        //public int Insert(string strSql, bool IsIdentity=false)
        //{
        //    try
        //    {
        //        Logger.Debug(string.Format("执行插入操作Sql：{0}", strSql));
        //        return IHelper.Insert(strSql, IsIdentity);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行插入操作失败Sql：{0}", strSql), ex);
        //    }
        //    return -1;
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="model">实体</param>
        ///// <param name="IsIdentity">是否返回自增字段</param>
        ///// <returns>返回-1表示执行失败</returns>
        //public int Insert(Entity model, bool IsIdentity=false)
        //{
        //    string strSql = IBuilder.Insert(model, TableName, KeyFieldName, IsIdentity);
        //    return Insert(strSql, IsIdentity);
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="fields">Dictionary<string, Object></param>
        ///// <param name="IsIdentity"></param>
        ///// <returns></returns>
        //public int Insert(Dictionary<string, Object> fields, bool IsIdentity = false)
        //{
        //    string strSql = IBuilder.Insert(fields, TableName, KeyFieldName, IsIdentity);
        //    return Insert(strSql, IsIdentity);
        //}

        //#endregion

        //#region update
        //public int Update(Dictionary<string, Object> fields, int ID)
        //{
        //    return Update(fields, string.Format("[{0}]={1}", KeyFieldName, ID));
        //}
        //public int Update(Dictionary<string, Object> fields, long ID)
        //{
        //    return Update(fields, string.Format("[{0}]={1}", KeyFieldName, ID));
        //}

        ///// <summary>
        ///// 不忽略Null值
        ///// </summary>
        ///// <param name="fields"></param>
        ///// <param name="Where"></param>
        ///// <returns></returns>
        //public int Update(Dictionary<string, Object> fields, string Where)
        //{
        //    string strSql = IBuilder.Update(fields, TableName, Where, KeyFieldName,false);
        //    try
        //    {
        //        Logger.Debug(string.Format("执行更新操作Sql：{0}", strSql));
        //        return IHelper.Update(strSql);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行更新操作失败Sql：{0}", strSql),
        //        ex);
        //    }
        //    return -1;
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="model"></param>
        ///// <param name="ID"></param>
        ///// <returns>返回-1执行失败</returns>
        //public int Update(Entity model, int ID, IList<string> ValidFields = null)
        //{
        //    return Update(model, string.Format("[{0}]={1}", KeyFieldName, ID), ValidFields);
        //}

        //public int Update(Entity model, long ID, IList<string> ValidFields = null)
        //{
        //    return Update(model, string.Format("[{0}]={1}", KeyFieldName, ID), ValidFields);
        //}

        ///// <summary>
        ///// 执行更新操作
        ///// </summary>
        ///// <param name="model"></param>
        ///// <param name="Where"></param>
        ///// <returns>返回-1表示操作失败</returns>
        //public int Update(Entity model, string Where, IList<string> ValidFields = null)
        //{
        //    string strSql = IBuilder.Update(model, TableName, Where, KeyFieldName,true,ValidFields);
        //    try
        //    {
        //        Logger.Debug(string.Format("执行更新操作Sql：{0}", strSql));
        //        return IHelper.Update(strSql);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行更新操作失败Sql：{0}", strSql),ex);
        //    }
        //    return -1;
        //}
        //#endregion

        //#region delete
        ///// <summary>
        ///// 执行删除操作
        ///// </summary>
        ///// <param name="ID"></param>
        ///// <returns>-1表示操作异常</returns>
        //public int Delete(int ID)
        //{
        //    string strWhere = string.Format(" [{0}]='{1}' ", KeyFieldName, ID);
        //    return Delete(strWhere);
        //}

        //public int Delete(long ID)
        //{
        //    string strWhere = string.Format(" [{0}]='{1}' ", KeyFieldName, ID);
        //    return Delete(strWhere);
        //}

        ///// <summary>
        ///// 执行删除操作
        ///// </summary>
        ///// <param name="Where"></param>
        ///// <returns>-1表示操作异常</returns>
        //public int Delete(string Where)
        //{
        //    string strSql = string.Format(" DELETE FROM [{0}] WHERE {1}", TableName, Where);
        //    try
        //    {
        //        Logger.Debug(string.Format("执行删除操作Sql：{0}", strSql));
        //        return IHelper.Delete(strSql);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行删除操作失败Sql：{0}", strSql),ex);
        //    }
        //    return -1;
        //}

        //#endregion

        //#region Other

        //public int Execute(string strSql)
        //{
        //    try
        //    {
        //        Logger.Debug(string.Format("执行Execute Sql：{0}", strSql));
        //        return IHelper.Execute(strSql);
        //    }
        //    catch(Exception ex) {
        //        Logger.Error(string.Format("执行[DAL.{0}] 失败Sql:{1}", "Execute",strSql), ex);
        //        return -1;
        //    }
        //}

        ///// <summary>
        ///// 是否存在
        ///// </summary>
        ///// <param name="where"></param>
        ///// <returns>存在返回true,失败返回false</returns>
        //public bool IsExist(string where)
        //{
        //    try
        //    {
        //        string strSql = string.Format("SELECT TOP 1 0 FROM {0} ", TableName);
        //        if (!string.IsNullOrEmpty(where))
        //        {
        //            strSql = strSql + " WHERE " + where;
        //        }
        //        Logger.Debug(string.Format("执行存在校验操作Sql：{0}", strSql));
        //        DataTable dt = Query(strSql).Tables[0];
        //        if (dt.Rows.Count > 0) return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行存在校验[DAL.{0}] 失败", "IsExist"),ex);
        //    }

        //    return false;
        //}

        ///// <summary>
        ///// 统计满足条件的记录数
        ///// </summary>
        ///// <param name="where"></param>
        ///// <returns></returns>
        //public int Count(string where)
        //{
        //    try
        //    {
        //        string strSql = string.Format("SELECT TOP 1 Count(*) FROM {0} ", TableName);
        //        if (!string.IsNullOrEmpty(where))
        //        {
        //            strSql = strSql + " WHERE " + where;
        //        }
        //        Logger.Debug(string.Format("执行数据统计Sql：{0}", strSql));
        //        DataTable dt = Query(strSql).Tables[0];
        //        if (dt.Rows.Count > 0) return TypeTools.ToInt(dt.Rows[0][0]);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行数据统计[DAL.{0}] 失败", "Count"),ex);
        //    }

        //    return 0;
        //}
        ///// <summary>
        ///// 统计满足条件的记录数
        ///// </summary>
        ///// <param name="sql"></param>
        ///// <returns></returns>
        //public int GetCountBySql(string strSql)
        //{
        //    try
        //    {
        //        Logger.Debug(string.Format("执行数据统计Sql：{0}", strSql));
        //        DataTable dt = Query(strSql).Tables[0];
        //        if (dt.Rows.Count > 0) return TypeTools.ToInt(dt.Rows[0][0]);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行数据统计[DAL.{0}] 失败", "Count"), ex);
        //    }

        //    return 0;
        //}
        ///// <summary>
        ///// 执行Sql存储过程
        ///// </summary>
        ///// <param name="StoredProcedureName">存储过程名字</param>
        ///// <param name="Parameters">参数</param>
        ///// <param name="IsReturn">是否有返回值</param>
        ///// <returns>返回对象，失败返回Null</returns>
        //public StoredReturnVlaue ProcRun(string StoredProcedureName, ProcParameters pms, bool IsReturn)
        //{
        //    try
        //    {
        //        Logger.Debug(string.Format("执行存储过程[{0}] ", StoredProcedureName));
        //        return IHelper.RunStore(StoredProcedureName, pms, IsReturn);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行存储过程[{0}] 失败", StoredProcedureName),ex);
        //        return null;
        //    }
        //}

        ///// <summary>
        ///// 执行插入存储过程
        ///// </summary>
        ///// <param name="StoredProcedureName">存储过程名字</param>
        ///// <param name="entity">实体</param>
        ///// <param name="NullValueIgnore">默认忽略值为Null的属性</param>
        ///// <returns>返回0表示执行失败</returns>
        //public int ProcInsert(string StoredProcedureName, Entity entity, bool NullValueIgnore = true)
        //{
        //    try
        //    {
        //        Logger.Debug(string.Format("执行插入存储过程[{0}] 失败", StoredProcedureName));
        //        ProcParameters spm = ModelConvert.ToSqlParameters(entity, NullValueIgnore, KeyFieldName);
        //       StoredReturnVlaue result= IHelper.RunStore(StoredProcedureName, spm,true);
        //       return TypeTools.ToInt( result.ReturnValue);
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error(string.Format("执行插入存储过程[{0}] 失败", StoredProcedureName),ex);
        //        return 0;
        //    }

        //}
        
        //public StoredReturnVlaue ProcPager(string OrderField, string sqlWhere, int pageSize, int pageIndex)
        //{
        //    return ProcPager(this.TableName, "*", OrderField, sqlWhere, pageSize, pageIndex);
        //}

        ///// <summary>
        ///// 执行分页存储过程
        ///// </summary>
        ///// <param name="TableName">表名</param>
        ///// <param name="Fields">返回字段</param>
        ///// <param name="OrderField">排序字段(必须 不带Order,支持多字段)</param>
        ///// <param name="sqlWhere">查询条件不带(Where)</param>
        ///// <param name="pageSize">每页记录数</param>
        ///// <param name="pageIndex">页码</param>
        ///// <param name="totalRecord">总记录数</param>
        ///// <returns></returns>
        //public StoredReturnVlaue ProcPager(string TableName, string Fields, string OrderField, string sqlWhere, int pageSize, int pageIndex)
        //{
        //    ProcParameters pm = new ProcParameters();
        //    pm.Add("TableName", TableName);
        //    pm.Add("Fields", Fields);
        //    pm.Add("OrderField", OrderField);
        //    pm.Add("sqlWhere", sqlWhere??"");
        //    pm.Add("pageSize", pageSize);
        //    pm.Add("pageIndex", pageIndex);
        //    pm.Add("totalRecord", 0);
        //    pm.Add("TotalPage", 0);
        //    StoredReturnVlaue sv = IHelper.RunStoreDataSet("[up_PagerList]", pm, true);
        //    pm = null;
        //    return sv;
        //}


        ///// <summary>
        ///// 执行分页存储过程
        ///// </summary>
        ///// <param name="TableName">表名</param>
        ///// <param name="Fields">返回字段</param>
        ///// <param name="OrderField">排序字段(必须 不带Order,支持多字段)</param>
        ///// <param name="sqlWhere">查询条件不带(Where)</param>
        ///// <param name="SqlWhere2">查询条件不带(SqlWhere2)条件带有 group by 写到这里 </param>
        ///// <param name="pageSize">每页记录数</param>
        ///// <param name="pageIndex">页码</param>
        ///// <param name="totalRecord">总记录数</param>
        ///// <returns></returns>
        //public StoredReturnVlaue ProcPager(string TableName, string Fields, string OrderField, string sqlWhere, string SqlWhere2, int pageSize, int pageIndex)
        //{
        //    ProcParameters pm = new ProcParameters();
        //    pm.Add("TableName", TableName);
        //    pm.Add("Fields", Fields);
        //    pm.Add("OrderField", OrderField);
        //    pm.Add("sqlWhere", sqlWhere ?? "");
        //    pm.Add("SqlWhere2", SqlWhere2 ?? "");
        //    pm.Add("pageSize", pageSize);
        //    pm.Add("pageIndex", pageIndex);
        //    pm.Add("totalRecord", 0);
        //    pm.Add("TotalPage", 0);
        //    StoredReturnVlaue sv = IHelper.RunStoreDataSet("[up_PagerList2]", pm, true);
        //    pm = null;
        //    return sv;
        //}


        ///// <summary>
        ///// 执行分页存储过程(Distance)
        ///// </summary>
        ///// <param name="TableName">表名</param>
        ///// <param name="Fields">返回字段</param>
        ///// <param name="OrderField">排序字段(必须 不带Order,支持多字段)</param>
        ///// <param name="sqlWhere">查询条件不带(Where)</param>
        ///// <param name="pageSize">每页记录数</param>
        ///// <param name="pageIndex">页码</param>
        ///// <param name="totalRecord">总记录数</param>
        ///// <param name="LngBegin">开始经度</param>
        ///// <param name="LatBegin">开始纬度</param>
        ///// <param name="FieldsLngBegin">结束经度</param>
        ///// <param name="FieldsLatBegin">结束纬度</param> 
        /////<returns></returns>
        //public StoredReturnVlaue ProcPager(string TableName, string Fields, string OrderField, string sqlWhere, int pageSize, int pageIndex, string LngBegin, string LatBegin, string FieldsLngBegin, string FieldsLatBegin)
        //{
        //    ProcParameters pm = new ProcParameters();
        //    pm.Add("TableName", TableName);
        //    pm.Add("Fields", Fields);
        //    pm.Add("OrderField", OrderField);
        //    pm.Add("sqlWhere", sqlWhere ?? "");
        //    pm.Add("pageSize", pageSize);
        //    pm.Add("pageIndex", pageIndex);
        //    pm.Add("totalRecord", 0);
        //    pm.Add("TotalPage", 0);
        //    pm.Add("LngBegin", 0);
        //    pm.Add("LatBegin", 0);
        //    pm.Add("FieldsLngBegin", 0);
        //    pm.Add("FieldsLatBegin", 0);
        //    StoredReturnVlaue sv = IHelper.RunStoreDataSet("[up_PagerListByDistance]", pm, true);
        //    pm = null;
        //    return sv;
        //}



        #endregion


    }//class
}//namespace
